package com.dataStructure.哈希表;

public class 计算哈希值 {
    public int calculationIntHash(Integer i){
        return i;
    }

    public int calculationFloatHash(Float f){
        return Float.floatToIntBits(f);
    }

    public int calculationLongHash(Long l){
        return (int) (l ^ (l >>> 32));
    }

    public int calculationDoubleHash(Double d){
        long bit = Double.doubleToLongBits(d);
        return (int) (bit ^ (bit >>> 32));
    }

    public int calculationStringHash(String s) {
        int hashCode = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
           //hashCode = (hashCode << 5) - hashCode + c;
            hashCode = 31 * hashCode + c;
        }
        return hashCode;
    }
}

